package org.simple.constant;

import lombok.Data;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

/**
 * 统一返回对象
 * @param <T>
 */
@Data
public class Result<T> implements Serializable {

	private Integer code;

	private String message;

	private T data;

	private Result(Integer code, String message,T data){
		this.code = code;
		this.message = message;
		this.data = data;
	}

	public static <T> Result<T> success(String message){
		return success(message,null);
	}

	public static <T> Result<T> success(String message,T data){
		return new Result<T>(HttpStatus.OK.value(),message,data);
	}

	public static <T> Result<T> error(String message){
		return new Result<>(HttpStatus.INTERNAL_SERVER_ERROR.value(),message,null);
	}



}
